<template>
  <div>
    <div class="my-course" v-for="(card,index) in course" :key="index">
      <div class="course-header">
        <h3 class="left">{{ card.courseTime }}</h3>
        <div class="right">
          <el-button type="text" v-if="card.state" @click="changeState(false,index)" class="launch-button">
            <i class="el-icon-caret-bottom icon"></i>展开
          </el-button>
          <el-button type="text" v-else @click="changeState(true,index)" class="launch-button">
            <i class="el-icon-caret-top icon"></i>收起
          </el-button>
        </div>
      </div>
      <transition name="card">
        <div class="topped-main" v-show="card.state === false">
          <div v-for="(item,index) in card.list" :key="index">
            <class-card :card="item" :courseTime="card.courseTime"></class-card>
          </div>
        </div>
      </transition>
    </div>
  </div>
</template>

<script>
import ClassCard from "@/components/mainpage/ClassCard.vue";

export default {
  data() {
    return {
      activeName: 'first',
      beforeData: '',
      afterData: '',
      course: '',
      newCourse: []
    }
  },
  components: {ClassCard},
  props: ['myCard'],
  methods: {
    changeState(state, index) {
      this.$set(this.course[index], 'state', state);
    },
  },
  mounted() {
    this.course = this.myCard.map(item => {
      return {
        ...item,
        state: true
      };
    });
    // this.$bus.$on('cancelTop', (data) => {
    //   this.course.forEach((item) => {
    //     if (data.courseCode === item.list.courseCode){
    //       console.log("找到可以取消置顶的课程")
    //       item.list.isTop = '0'
    //     }
    //   })
    // })

  },
  watch: {
    myCard(newVal) {
      this.course = newVal.map(item => {
        return {
          ...item,
          state: true
        };
      });
    }
  }
}
</script>

<style scoped>
.card-leave-active,
.card-enter-active {
  transition: all 1s ease;
}

.card-leave-to,
.card-enter {
  height: 0;
}

.card-leave,
.card-enter-to {
  height: 336px;
}

.my-course {
  max-width: 1470px;
  background: #f8f9fa;
  margin: 0 auto 24px;
  border: 1px solid #dadce0;
  border-radius: 8px;
  padding: 18px;
}

.course-header {
  display: flex;
  flex-flow: nowrap;
  justify-content: space-between;
}

.left {
  font-size: 21px;
  font-weight: 400;
  font-family: Roboto, Helvetica, Arial, sans-serif;
}

.launch-button {
  font-size: 19px;
  margin-right: 32px;
}

.icon {
  margin-right: 8px;
}

.class-box {
  margin: 8px -10px 0;
  display: flex;
  flex-flow: row wrap;
  overflow-y: auto;
}

.topped-main {
  max-height: 350px;
  margin: 0 -10px 0;
  display: flex;
  flex-flow: row wrap;
  overflow-y: hidden;
}

.main-card {
  margin: 13px;
  width: 325px;
  height: 310px;
  background: #fff;
  border: 1px solid #e2e6ed;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}

.card-header {
  cursor: pointer;
  padding: 24px 30px;
  height: 180px;
  color: #fff;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: 50%;
  background-color: #3367d5;
  background-image: url("../../assets/img/main/myclassimg.png");
}

.time {
  opacity: 0.6;
  font-size: 16px;
}

.name {
  margin-top: 7px;
  font-size: 24px;
  font-family: PingFangSC, PingFangSC-Medium, sans-serif;
  font-weight: 500;
  text-align: left;
  color: #fff;
  line-height: 32px;
}

.classname {
  font-family: PingFangSC, PingFangSC-Medium, sans-serif;
  font-weight: 500;
  text-align: left;
  color: #fff;
  line-height: 38px;
  font-size: 16px;
}

.qrcode {
  margin-top: 18px;
  display: flex;
  position: relative;
  font-size: 12px;
  font-family: PingFangSC, PingFangSC-Medium, sans-serif;
  font-weight: 500;
  text-align: left;
  color: #fff;
  line-height: 16px;
}

.qrcode img {
  display: block;
  width: 16px;
  margin-right: 8px;
}

.qrcode span {
  font-size: 18px;
}

.card-content {
  cursor: pointer;
  height: 70px;
  padding: 0 20px 16px 20px;
}

.card-foot {
  display: flex;
  justify-content: space-between;
  height: 40px;
  padding: 8px 14px 12px;
  font-size: 12px;
  line-height: 16px;
  font-family: PingFangSC, PingFangSC-Regular, sans-serif;
  font-weight: 400;
  text-align: left;
  color: #3c4043;
}

.left {
  display: flex;
  align-items: center;
}

.res-person {
  font-size: 18px;
  cursor: pointer;

}

.right {
  display: flex;
  align-items: center;
  font-size: 16px;
  font-family: PingFangSC, PingFangSC-Medium, sans-serif;
  font-weight: 500;
  color: black;
}

.set-top {
  cursor: pointer;
  display: flex;
  align-items: center;
}

.set-top img {
  display: block;
  width: 17px;
  margin-right: 4px;
}

.three-point {
  cursor: pointer;
  margin-left: 11px;
}

.el-dropdown-link {
  cursor: pointer;
}

.el-icon-arrow-down {
  font-size: 12px;
}


::v-deep .el-dropdown-menu__item {
  font-size: 18px;
}
</style>
